package spring.cloud.tasks.tasks_manager.task_item_assign.pick_up.task;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import spring.cloud.tasks.common.curator.Curator;
import spring.cloud.tasks.common.task_item_allot.Executor;
import spring.cloud.tasks.common.task_item_allot.TaskItem;
import spring.cloud.tasks.tasks_manager.task_item_assign.PreferExecutorSettings;
import spring.cloud.tasks.tasks_manager.task_item_assign.TaskItemAssignUtils;
import spring.cloud.tasks.tasks_manager.task_item_assign.pick_up.PickUp;

import java.util.List;

/**
 * Task Disable，摘取所有executor运行的该任务的Task Item,同时扣减executor的loadLevel,不需要放回
 */
@Slf4j
@Setter
@Getter
public class PickUpWhenTaskDisable extends PickUp {
    private String taskId;


    @Override
    protected void log() {
        log.info("Execute the {} with {} disable", this.getClass().getSimpleName(), taskId);
    }

    @Override
    public boolean pickUp(Curator curator,//
                          List<String> taskIdList,//
                          List<String> enableTaskIdList,//
                          List<TaskItem> pickUpEdTaskItemList,//
                          List<TaskItem> discardTaskItemList,//
                          List<Executor> onlineExecutorList,//
                          List<Executor> ownTrafficOnlineExecutorList,//
                          PreferExecutorSettings preferExecutorSettings) {
        List<TaskItem> removedTaskItemList = TaskItemAssignUtils.removeTaskItemListOfTask(ownTrafficOnlineExecutorList, taskId);
        discardTaskItemList.addAll(removedTaskItemList);
        return true;
    }


}
